﻿@using OJS.Common.Extensions;
@using OJS.Common.Models;
@using OJS.Web.Areas.Contests.ViewModels.Contests

@using Resource = Resources.Areas.Contests.Views.ContestsDetails;

@model ContestViewModel

@{
    ViewBag.Title = Model.Name;
}

<ol class="breadcrumb">
    <li><a href="/">@Resource.Home</a></li>
    <li>@Html.ActionLink(Resource.Contests, GlobalConstants.Index, "List")</li>
    <li class="active">@Model.Name</li>
</ol>

<h1 class="text-center">@ViewBag.Title</h1>

<div class="row">
    <div class="col-md-8">
        <h3>@Resource.Contest_details</h3>
        @if (Model.CanBeCompeted && Model.EndTime != null)
        {
            <h5>
                @Resource.Competition_active_until: @Model.EndTime.Value.ToString("hh:mm d.M.yyy")
            </h5>
        }
        @if (Model.CanBePracticed && Model.PracticeEndTime != null)
        {
            <h5>@Resource.Practice_active_until: @Model.PracticeEndTime.Value.ToString("hh:mm d.M.yyy")</h5>
        }
        @if (!string.IsNullOrEmpty(Model.Description))
        {
            @Model.Description
        }
        else
        {
            <div>@Resource.No_contest_description</div>
        }
        <h5>
            @Resource.Allowed_languages: |
            @foreach (var submissionType in Model.AllowedSubmissionTypes)
            {
                <span>
                    @Html.ActionLink(
                        submissionType.Name, 
                        "BySubmissionType", 
                        new { controller = "List", id = submissionType.Id, submissionTypeName = submissionType.Name.ToUrl() 
                    }) |
                </span>
            }
        </h5>
        <h5>
            @Resource.Contest_participants: @Model.OfficialParticipants
        </h5>
        <h5>
            @Resource.Practice_participants: @Model.PracticeParticipants
        </h5>
    </div>
    <div class="col-md-4 col-sm-12" style="margin: 0 auto;">
        <h3>@Resource.Problems</h3>
        @if ((Model.CanBePracticed && !Model.HasPracticePassword) || (Model.CanBeCompeted && !Model.HasContestPassword))
        {
            foreach (var problem in Model.Problems)
            {
                <h4>@problem.Name</h4>
                foreach (var resource in problem.Resources)
                {
                    var resourceLink = string.IsNullOrWhiteSpace(resource.Link) ?
                                        Url.Action("DownloadResource", new { controller = "Practice", id = resource.ResourceId }) : resource.Link;
                    <p>
                        @if (resource.ProblemType == ProblemResourceType.ProblemDescription)
                        {
                            <span class="glyphicon glyphicon-list-alt resource-glyph"></span>
                        }
                        else if (resource.ProblemType == ProblemResourceType.AuthorsSolution)
                        {
                            <span class="glyphicon glyphicon-thumbs-up resource-glyph"></span>
                        }
                        else if (resource.ProblemType == ProblemResourceType.Video)
                        {
                            <span class="glyphicon glyphicon-facetime-video resource-glyph"></span>
                        }
                        else
                        {
                            <span class="glyphicon  glyphicon-question-sign"></span>
                        }
                        <a href="@resourceLink" target="_blank" class="resource-link">@resource.Name</a>
                    </p>
                }
            }
        }
        else
        {
            <text>
                <p>@Resource.Problems_are_not_public</p>
            </text>
        }
    </div>
</div>

<div class="row">
    <div class="col-md-12 text-center">
        @if (Model.CanBeCompeted)
        {
            @Html.ActionLink(Resource.Compete, GlobalConstants.Index, new { controller = "Compete", id = Model.Id }, new { @class = "btn btn-sm btn-success" })
        }
        @if (Model.CanBePracticed)
        {
            @Html.ActionLink(Resource.Practice, GlobalConstants.Index, new { controller = "Practice", id = Model.Id }, new { @class = "btn btn-sm btn-primary" })
        }
        @if (User.IsAdmin())
        {
            <a class="btn btn-sm btn-primary" href="/Contests/Compete/Results/Simple/@Model.Id">@Resource.Results</a>
            <a class="btn btn-sm btn-primary" href="/Contests/Compete/Results/Full/@Model.Id">@Resource.Full_results</a>
            <a class="btn btn-sm btn-primary" href="/Administration/Contests/Edit/@Model.Id">@Resource.Edit</a>
            <a class="btn btn-sm btn-primary" href="/Administration/Problems/Contest/@Model.Id">@Resource.Problems</a>
        }
    </div>
</div>

@if (User.Identity.IsAuthenticated)
{
    Html.RenderPartial("_AllContestSubmissionsByUser");
}